//
//  PickerTableViewCell.m
//  ATMCash
//
//  Created by zhengchengfeng on 2024/9/12.
//

#import "PickerTableViewCell.h"

@implementation PickerTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backgroundColor = [UIColor clearColor];
        
        self.picV = [[UIImageView alloc] init];
        [self.contentView addSubview:self.picV];
        [self.picV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.with.height.equalTo(@0);
            make.top.equalTo(self.contentView.mas_top);
            make.left.equalTo(self.contentView.mas_left);
        }];
        
        self.titleLab = [Utility createLabel:[UIFont fontWithName:kFuturaMedium size:14] color:[UIColor colorWithHexString:@"#022D06"]];
        [self.contentView addSubview:self.titleLab];
        [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(15);
            make.right.equalTo(self.contentView.mas_right).offset(-45);
            make.top.equalTo(self.contentView.mas_top);
            make.bottom.equalTo(self.contentView.mas_bottom);
        }];
        
        self.iconV = [[UIImageView alloc] init];
        [self.contentView addSubview:self.iconV];
        [self.iconV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.with.height.equalTo(@20);
            make.right.equalTo(self.contentView.mas_right).offset(-15);
            make.centerY.equalTo(self.titleLab.mas_centerY);
        }];
        
    }
    return self;
}

- (void)setModel:(FrightensModel *)model{
    _model = model;
    self.titleLab.text = esString(model.cambridge);
    if (model.isShow) {
        self.iconV.image = [UIImage imageNamed:@"icon_per5"];
        self.titleLab.textColor = [UIColor colorWithHexString:@"#00BA60"];
    } else {
        self.iconV.image = [UIImage imageNamed:@"icon_per4"];
        self.titleLab.textColor = [UIColor colorWithHexString:@"#022D06"];
    }
    
    
    [self.picV sd_setImageWithURL:[NSURL URLWithString:esString(model.spoon)]];
    
    if (PMStringIsEmpty(model.spoon)) {
        self.picV.hidden = YES;
        [self.picV mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.width.with.height.equalTo(@0);
            make.top.equalTo(self.contentView.mas_top);
            make.left.equalTo(self.contentView.mas_left);
        }];
        [self.titleLab mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(15);
            make.right.equalTo(self.contentView.mas_right).offset(-45);
            make.top.equalTo(self.contentView.mas_top);
            make.bottom.equalTo(self.contentView.mas_bottom);
        }];
        
    }
    else {
        self.picV.hidden = NO;
        [self.picV mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.width.with.height.equalTo(@28);
            make.top.equalTo(self.contentView.mas_top).offset(10);
            make.left.equalTo(self.contentView.mas_left).offset(15);
        }];
        [self.titleLab mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.picV.mas_right).offset(5);
            make.right.equalTo(self.contentView.mas_right).offset(-45);
            make.top.equalTo(self.contentView.mas_top);
            make.bottom.equalTo(self.contentView.mas_bottom);
        }];
    }
    

}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
